package com.qihetimes.earthangel.controller;

import com.qihetimes.earthangel.common.ResponseResult;
import com.qihetimes.earthangel.model.User;
import com.qihetimes.earthangel.model.bo.PageBO;
import com.qihetimes.earthangel.model.vo.PageVO;
import com.qihetimes.earthangel.model.vo.UserVO;
import com.qihetimes.earthangel.service.IFriendRelationService;
import com.qihetimes.earthangel.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 好友
 *
 * @author ：f4cklangzi@gmail.com
 * @date ：Created At 2021/12/18
 */
@Slf4j
@Api(tags = "好友模块")
@RestController
@RequestMapping("/api/friend")
public class FriendController {
    
    @Resource
    private IUserService userService;
    
    @Resource
    private IFriendRelationService friendRelationService;
    
    @ApiOperation(value = "好友列表")
    @PostMapping("/list")
    public ResponseResult<PageVO<UserVO>> friendList(@RequestBody PageBO param) {
        User loginUser = userService.getLoginUser();
        PageVO<UserVO> friendListPage = friendRelationService.getFriendList(loginUser.getId(), param.getPageNum(),
            param.getPageSize());
        return ResponseResult.success(friendListPage);
    }
    
    @ApiOperation(value = "添加好友")
    @PostMapping("/add")
    public ResponseResult<String> add(@RequestParam String userId) {
        friendRelationService.add(userId);
        return ResponseResult.success();
    }
    
    @ApiOperation(value = "删除好友")
    @DeleteMapping("/delete")
    public ResponseResult<String> delete(@RequestParam String userId) {
        friendRelationService.delete(userId);
        return ResponseResult.success();
    }
}
